import win32gui
import win32com
import win32com.client
import pythoncom
import time
      
class EventHandler:
    def OnVisible(self, visible):
        global bVisibleEventFired
        bVisibleEventFired = 1
    def OnDownloadBegin(self):
        print "DownloadBegin"
        global testlist
        testlist.append("DownloadBegin")
    def OnDownloadComplete(self):
        print "DownloadComplete"
        global testlist
        testlist.append("DownloadComplete")
    def OnDocumentComplete(self, pDisp = pythoncom.Missing , URL = pythoncom.Missing):
        print "documentComplete of %s" % URL
        global testlist
        print testlist

class runcom:
    def __init__(self):
        global testlist
        ie = win32com.client.DispatchWithEvents("InternetExplorer.Application", EventHandler)
        ie.Visible = 1
        ie.Navigate("www.baidu.com")
        print testlist
        pythoncom.PumpMessages()
        ie.Quit()
testlist=[]
a=runcom()
